package com.ringtheweb.web.action;


import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;



@Name("locationAction")
@Scope(ScopeType.STATELESS)
public class LocationAction {
	
//	@In(create=true,value="entityManager")
//	private EntityManager em;
//	
//	
//	/**
//	 * Search location by id.
//	 * @param id
//	 * @return
//	 */
//	public Location loadById(Long id) {
		
//		List<Location> locations= null;
//		Query query = em.createNamedQuery(FIND_LOCATION_WITHOUT_CHILDREN).setParameter("locationId", id);
//		if ((locations=(List<Location>)query.getResultList()).size() > 0) {
//			return locations.get(0);
//		}
		
//		return null;
//	}
//	
//	/**
//	 * Search location by level.
//	 * @param level
//	 * @return
//	 */
//	@SuppressWarnings("unchecked")
//	public Collection<Location> loadByLevel(Integer level) {
//		return em.createQuery("SELECT l FROM biz.dewavrin.seamphony.data.Location l where l.level=:level order by l.name asc").setParameter("level", level).getResultList();
//	}
//	
//	
//	// TODO: see load by example.
//	@SuppressWarnings("unchecked")
//	public Collection<Location> loadByNameAndParent(String name,long id) {
//		return em.createQuery("select l from biz.dewavrin.seamphony.data.Location l where l.parent=:parentId and l.name like :name")
//				.setParameter("parentId", id)
//				.setParameter("name", name)
//				.getResultList();
//	}
//	
//	
	
//	public Collection<LocationData> loadDataByNameAndParent(String name,long id) {
//		return fromLocation(loadByNameAndParent(name, id));
//	}
//	
//	
//	/**
//	 * Search by id.
//	 * @param id
//	 * @return
//	 */
//	public LocationData loadDataById(Long id) {
//		return fromLocation(loadById(id));
//	}
//	
//	
//	/**
//	 * Search by level.
//	 * @param level
//	 * @return
//	 */
//	public Collection<LocationData> loadDataByLevel(Integer level) {
//		return fromLocation(loadByLevel(level));
//	}
//	
//	/**
//	 * Convert a {@link Location} to {@link LocationData}
//	 * @param location
//	 * @return
//	 */
//	public LocationData fromLocation(Location location) {
//		LocationData locData = new LocationData();
//		locData.setId(location.getId());
//		locData.setName(location.getName());
//		locData.setLocationType(location.getLocationType());
//		
//		return locData;
//	}
//	
//	public Collection<LocationData>  fromLocation(Collection<Location> locations) {
//		List<LocationData> locationsData =  new ArrayList<LocationData>();
//		for (Location location : locations) {
//			locationsData.add(fromLocation(location));
//		}
//		return locationsData;
//	}
 
}
